package com.example.demo.mapper;


import com.example.demo.pojo.Mysell;
import com.example.demo.pojo.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author yanglup
 * @create 2020-11-23 20:42
 */
@Mapper
public interface OrdersMapper {
    /**创建订单 (select status from goodsaddtable where goods_id=#{goods_id})*/
    @Insert("insert into createordertable(openid,openidbuy,consignee_addr,order_price,goods_id,goods_number,goods_price,order_status,goods_name,order_number,buyer,seller,goods_small_logo) " +
            "values ((select openid from goodsaddtable where goods_id=#{goods_id}),#{openidbuy},#{consignee_addr},#{order_price},#{goods_id},#{goods_number},#{goods_price},1,(select goods_name from goodsaddtable where goods_id=#{goods_id})," +
            "(select goods_serial from goodsaddtable where goods_id=#{goods_id}),0,0,(select goods_small_logo from goodsaddtable where goods_id=#{goods_id}));")
    void createorderstableinsert(String openidbuy, String consignee_addr, Integer order_price, Integer goods_id, Integer goods_number, Integer goods_price);
    /**修改订单状态 0-->1    创建时修改了创建表的状态， 这里修改了添加表的状态*/
    @Update("update goodsaddtable set status=1 where goods_id=#{goods_id};")
    void updatestatus(Integer goods_id);




    /**点击发货发货的1--买方显示待发货信息*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openidbuy=#{openidbuy} and order_status=1;")
    List<Order> awaitorders(String openidbuy);
    /**待收货*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openidbuy=#{openidbuy} and order_status=2;")
    List<Order> awairece(String openidbuy);
    /**退款*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openidbuy=#{openidbuy} and order_status=3;")
    List<Order> tuikuan(String openidbuy);
    /**全部*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openidbuy=#{openidbuy} and (order_status=4 or order_status=5);")
    List<Order> allorders(String openidbuy);

    /**修改为退款状态*/
    @Update("update createordertable set order_status=3 where goods_id=#{goods_id};")
    void clicktuikuancre(Integer goods_id);
    @Update("update goodsaddtable set status=3 where goods_id=#{goods_id};")
    void clicktuikuangood(Integer goods_id);

    /**修改为确认状态*/
    @Update("update createordertable set order_status=4 where goods_id=#{goods_id};")
    void confirmgetcre(Integer goods_id);
    @Update("update goodsaddtable set status=4 where goods_id=#{goods_id};")
    void confirmgetgood(Integer goods_id);

    /**申请退货*/
    @Update("update createordertable set buyer=1 where openidbuy=#{openidbuy} and goods_id=#{goods_id};")
    void applyreturngoodscre(String openidbuy, Integer goods_id);




    /**卖家已经发货*/
    @Update("update createordertable set order_status=2 where goods_id=#{goods_id};")
    void delivergoodscre(Integer goods_id);
    /**卖家已经发货*/
    @Update("update goodsaddtable set status=2 where goods_id=#{goods_id};")
    void delivergoodsgood(Integer goods_id);


/**--------------------------------------卖家----------------------------------------------------*/
    /**卖家同意退货*/
    @Update("update createordertable set seller=1 where openid=#{openid} and goods_id=#{goods_id};")
    void agreereturn(String openid, Integer goods_id);
    /**状态改变为5*/
    @Update("update createordertable set order_status=5 where goods_id=#{goods_id} and buyer=1 and seller=1;")
    void agreereturnzhuangtai4(Integer goods_id);
    /***/
    @Update("update goodsaddtable set status=5 where goods_id=#{goods_id};")
    void agreereturngood(Integer goods_id);


    /**待发货*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openid=#{openid} and order_status=1;")
    List<Order> selldaifahuo(String openid);
    /**待收货*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openid=#{openid} and order_status=2;")
    List<Order> sellyifahuo(String openid);
    /**退款*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openid=#{openid} and order_status=3;")
    List<Order> selltuihuo(String openid);
    /**卖家全部订单*/
    @Select("select  order_id,consignee_addr,goods_id,order_number,order_status,goods_number,order_price,goods_name,goods_small_logo,goods_price " +
            "from createordertable where openid=#{openid} and (order_status=4 or order_status=5);")
    List<Order> sellallgoods(String openid);




    /**--------------------------------mysell------------------------------------------------*/
    @Select("select goods_id,goods_name,goods_price,goods_small_logo from goodsaddtable where openid=#{openid} and status=0;")
    List<Mysell> mysell(String openid);
    @Select("select count(*) from goodsaddtable where openid=#{openid} and status=0;")
    Integer mysellcount(String openid);



}
